package com.csb.controller;

import com.csb.config.MyConstants;
import com.csb.pojo.Apply;
import com.csb.pojo.UserInfo;
import com.csb.service.AroService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/aro")
public class AroController {
    // 依赖
    @Autowired
    private AroService aroService;

    /**
     * 获取待审批一览
     *
     * @return
     */
    @RequestMapping("/noApprovalList")
    public List<Apply> noApprovalList() {
        return aroService.getApprovalNoList(MyConstants.APPLY_INIT);
    }

    /**
     * 同意资产的申请
     *
     * @param ids
     * @return
     */
    @RequestMapping("/yes")
    public String yesApplyInfo(String[] ids) {
        // 获取账号
        UserInfo userInfo = (UserInfo) SecurityUtils.getSubject().getPrincipal();
        //获取审批者账号
        String approvalAccount = userInfo.getAccount();
        if (aroService.yesApplyInfo(ids, approvalAccount)) {
            return "1";
        } else {
            return "0";
        }
    }

    /**
     * 不同意资产的申请
     *
     * @param ids
     * @param session
     * @return
     */
    @RequestMapping("/no")
    public String noApplyInfo(String[] ids, HttpSession session) {
        //获取当前用户
        UserInfo user = (UserInfo) session.getAttribute("user");
        //获取审批者账号
        String approvalAccount = user.getAccount();
        if (aroService.noApplyInfo(ids, approvalAccount)) {
            return "1";
        } else {
            return "0";
        }
    }

}
